home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSNEXT.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  89 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lsnext.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* local headers */
  12. #include "lseq_.h"
  13.  
  14. /*man---------------------------------------------------------------------------
  15. NAME
  16.      lsnext - next lseq record
  17.  
  18. SYNOPSIS
  19.      #include <lseq.h>
  20.  
  21.      int lsnext(lsp)
  22.      lseq_t *lsp;
  23.  
  24. DESCRIPTION
  25.      The lsnext function advances the cursor of lseq lsp to the next
  26.      record.  If the cursor is currently null, it will be advanced to
  27.      the first record.  If the cursor is currently on the last record,
  28.      it will be advanced to null.  If lsp is empty, the cursor will
  29.      remain set to null.
  30.  
  31.      lsnext will fail if one or more of the following is true:
  32.  
  33.      [EINVAL]       lsp is not a valid lseq pointer.
  34.      [LSELOCK]      lsp is not locked.
  35.      [LSENOPEN]     lsp is not open.
  36.  
  37. SEE ALSO
  38.      lscursor, lsfirst, lslast, lsprev.
  39.  
  40. DIAGNOSTICS
  41.      Upon successful completion, a value of 0 is returned.  Otherwise,
  42.      a value of -1 is returned, and errno set to indicate the error.
  43.  
  44. ------------------------------------------------------------------------------*/
  45. #ifdef AC_PROTO
  46. int lsnext(lseq_t *lsp)
  47. #else
  48. int lsnext(lsp)
  49. lseq_t *lsp;
  50. #endif
  51. {
  52.     /* validate arguments */
  53.     if (!ls_valid(lsp)) {
  54.         errno = EINVAL;
  55.         return -1;
  56.     }
  57.  
  58.     /* check if not open */
  59.     if (!(lsp->flags & LSOPEN)) {
  60.         errno = LSENOPEN;
  61.         return -1;
  62.     }
  63.  
  64.     /* check if not locked */
  65.     if (!(lsp->flags & LSLOCKS)) {
  66.         errno = LSELOCK;
  67.         return -1;
  68.     }
  69.  
  70.     /* advance cursor */
  71.     if (lsp->clspos == NIL) {
  72.         lsp->clspos = lsp->lshdr.first;
  73.     } else {
  74.         lsp->clspos = lsp->clsrp->next;
  75.     }
  76.  
  77.     /* read in new current record */
  78.     if (lsp->clspos == NIL) {
  79.         ls_rcinit(lsp, lsp->clsrp);
  80.     } else {
  81.         if (ls_rcget(lsp, lsp->clspos, lsp->clsrp) == -1) {
  82.             LSEPRINT;
  83.             return -1;
  84.         }
  85.     }
  86.  
  87.     return 0;
  88. }
  89.